home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: sprintf() question
- Date: Wed, 27 Mar 96 21:07:55 GMT
- Organization: none
- Message-ID: <827960875snz@genesis.demon.co.uk>
- References: <31593522.76B3@cbm.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <31593522.76B3@cbm.com> paynedc@cbm.com "Dave Payne" writes:
-
- >Question on sprintf():
- >
- >Is it safe, and more importantly, is it ANSI standard, to use sprintf()
- >to print into the same variable? Consider this example:
- >
- >char foo[100] = "foobar";
- >
- >sprintf(foo,"%s%s","the string is",foo);
-
- The standard says:
-
- 7.9.6.5 The sprintf function
-
- "If copying takes place between objects that overlap, the behaviour is
- undefined"
-
- So this code is illegal.
-
- >Would the resulting string be "the string is foobar", or will this
- >code cause problems because I'm using the same variable (foo) to
- >print to as well as read from?
-
- Anything at all can happen.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-